﻿using B.S.RbacData.Domain;
using B.S.RbacData.ErrorCode;
using B.S.RbacData.Infrastructure;
using B.S.RbacData.Read.API.Applications.Commands.RBAC;
using MediatR;
using Microsoft.EntityFrameworkCore;

namespace B.S.RbacData.Read.API.Applications.CommandHandlters.RBAC
{
    /// <summary>
    /// 获取角色权限处理
    /// </summary>
    public class GetRoleIdCommandHandlter : IRequestHandler<GetRoleIdCommand, ApiResult<List<int>>>
    {
        private readonly IBaseRepository<RolePermissionModel> rolepermissionRep;

        public GetRoleIdCommandHandlter(IBaseRepository<RolePermissionModel> rolepermissionRep)
        {
            this.rolepermissionRep = rolepermissionRep;
        }

        public async Task<ApiResult<List<int>>> Handle(GetRoleIdCommand request, CancellationToken cancellationToken)
        {

            var rolepermission =await rolepermissionRep.GetAll().Where(x => x.RoleId == request.RoleId).Select(x=>x.PermissionId).ToListAsync();


            return new ApiResult<List<int>>
            {
                code = ResultEnumCode.Ok,
                data = rolepermission,
                message="查询成功"


            };


        }
    }
}
